package com.ethanzzh.security.ethanzzhdemo.wiremock;

import com.github.tomakehurst.wiremock.client.WireMock;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;

public class mockServer {
    public static void main(String[] args) throws IOException {
        WireMock.configureFor(8082);
        WireMock.removeAllMappings();

        mock("/order/1","01");
        mock("/order/2","02");



    }

    private static void mock(String url, String file) throws IOException {

        ClassPathResource resource = new ClassPathResource(file + ".txt");
        String content = StringUtils.join(FileUtils.readLines(resource.getFile(),"UTF-8").toArray(), "\n");
        WireMock.stubFor(WireMock.get(WireMock.urlEqualTo(url))
                .willReturn(WireMock.aResponse()
                        .withBody(content).withStatus(200)));
    }
}
